package com.qeado.content.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.qeado.admin.common.BaseConstData;
import com.qeado.common.helper.AttributeHelper;
import com.qeado.content.model.MessageBoard;
import com.qeado.content.service.MessageBoardService;

@Controller
public class MessageBoardManageController {
	@Autowired
	private MessageBoardService messageBoardService;
	
	@RequestMapping("/messageBoardManage.ac")
	public String messageBoardManage(HttpServletRequest request){
		AttributeHelper.removeSessionAttribute(request, "T_");
		return "content/message_board_search";
	}
	
	@RequestMapping("/messageBoardSearch.ac")
	public String messageBoardSearch(HttpServletRequest request, MessageBoard messageBoard){
		List<MessageBoard> messageBoardList = messageBoardService.messageBoardSearch(messageBoard);
		request.setAttribute("messageBoardList", messageBoardList);
		return "content/message_board_search";
	}
	
	@RequestMapping("/selectMessageBoard.ac")
	public ModelAndView selectMessageBoard(String id){
		MessageBoard messageBoard = messageBoardService.selectMessageBoard(id);
		return new ModelAndView("content/message_board_manage", "messageBoard", messageBoard);
	}
	
	@RequestMapping("/deleteMessageBoard.ac")
	public ModelAndView deleteMessageBoard(HttpServletRequest request, String id){
		messageBoardService.deleteMessageBoard(id);
		List<MessageBoard> messageBoardList = messageBoardService.messageBoardSearch(null);
		return new ModelAndView("content/message_board_search", "messageBoardList", messageBoardList);
	}
	
	@RequestMapping("/saveMessageBoard.ac")
	public String saveMessageBoard(HttpServletRequest request, MessageBoard messageBoard){
		messageBoard.setModifier(request.getSession().getAttribute(BaseConstData.USER_ID).toString());
		String message = messageBoardService.saveMessageBoard(messageBoard);
		request.setAttribute("message", message);
		return "content/message_board_manage";
	}

}
